import json
import requests
from  datetime import datetime

def get_ip_info(ip):
    r = requests.get('https://ip.taobao.com/outGetIpInfo?accessKey=alibaba-inc&ip=%s' % ip)
    if r.json()['code'] == 0:
        i = r.json()['data']
        country = i['country']
        region = i['region']
        isp = i['isp']
        print(f'国家：{country},地区: {region},运营商: {isp}')
        #print(i)
    else:
        print('未查到归属地和运营商')
#get_ip_info("120.25.208.128")
with open('weblog.txt',) as fp:
    lst = []
    for i in fp.readlines():
        lst.append(i.split(" "))
    for i in range(len(lst)):
        ti = datetime.strptime(lst[i][3][1:], '%d/%b/%Y:%H:%M:%S')
        print(f'ip: {lst[i][0]}, 时间：{ti}, 带宽：{lst[i][9]}', end=' ')
        get_ip_info(lst[i][0])


